from fractions import Fraction

from algorithm.comparison import compare_list
from polynomial.polynomial import Polynomial

__all__ = ["PolynomialQ"]



class PolynomialQ(Polynomial):

    __slots__ = ("_coeff",)
    member_type = Fraction
    zero = Fraction(0)
    one = Fraction(1)

    def __lt__(self, other):
        l1 = len(self._coeff)
        l2 = len(other._coeff)
        if l1 < l2:
            return True
        elif l1 > l2:
            return False
        for x, y in zip(reversed(self._coeff), reversed(other._coeff)):
            comparison = compare_list(abs, lambda x: x)(x, y)
            if comparison < 0:
                return True
            elif comparison > 0:
                return False
        return False
